package com.smart.system.service.impl;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.smart.common.utils.DateUtils;
import com.smart.system.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smart.system.mapper.EmployeeTrajectoryMapper;
import com.smart.system.domain.EmployeeTrajectory;
import com.smart.system.service.IEmployeeTrajectoryService;

/**
 * 员工移动轨迹Service业务层处理
 * 
 * @author smart
 * @date 2024-09-18
 */
@Service
public class EmployeeTrajectoryServiceImpl extends ServiceImpl<EmployeeTrajectoryMapper,EmployeeTrajectory> implements IEmployeeTrajectoryService {


    @Autowired
    @Lazy
    private IEmployeeService employeeService;
    /**
     * 查询员工移动轨迹
     * 
     * @param id 员工移动轨迹主键
     * @return 员工移动轨迹
     */
    @Override
    public EmployeeTrajectory selectEmployeeTrajectoryById(String id)
    {
        EmployeeTrajectory employeeTrajectory = this.baseMapper.selectById(id);
        employeeTrajectory.setEmployee(employeeService.getById(String.valueOf(employeeTrajectory.getUserId())));
        return employeeTrajectory;
    }

    /**
     * 查询员工移动轨迹列表
     * 
     * @param employeeTrajectory 员工移动轨迹
     * @return 员工移动轨迹
     */
    @Override
    public List<EmployeeTrajectory> selectEmployeeTrajectoryList(EmployeeTrajectory employeeTrajectory)
    {
        return this.list(Wrappers.lambdaQuery(employeeTrajectory).orderByDesc(EmployeeTrajectory::getCreateTime));
    }

    /**
     * 新增员工移动轨迹
     * 
     * @param employeeTrajectory 员工移动轨迹
     * @return 结果
     */
    @Override
    public int insertEmployeeTrajectory(EmployeeTrajectory employeeTrajectory)
    {
        employeeTrajectory.setCreateTime(DateUtils.getNowDate());
        return this.baseMapper.insert(employeeTrajectory);
    }

    /**
     * 修改员工移动轨迹
     * 
     * @param employeeTrajectory 员工移动轨迹
     * @return 结果
     */
    @Override
    public int updateEmployeeTrajectory(EmployeeTrajectory employeeTrajectory)
    {
        employeeTrajectory.setUpdateTime(DateUtils.getNowDate());
        return this.baseMapper.updateById(employeeTrajectory);
    }

    /**
     * 批量删除员工移动轨迹
     * 
     * @param ids 需要删除的员工移动轨迹主键
     * @return 结果
     */
    @Override
    public int deleteEmployeeTrajectoryByIds(String[] ids)
    {
        return this.baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除员工移动轨迹信息
     * 
     * @param id 员工移动轨迹主键
     * @return 结果
     */
    @Override
    public int deleteEmployeeTrajectoryById(String id)
    {
        return this.baseMapper.deleteById(id);
    }
}
